﻿Imports System
Imports System.IO
Imports System.Drawing
Imports System.Drawing.Font
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Data
Imports System.Drawing.Text


Public Class frmCarnetEmpleado

    Public Sub Mostrar()
        If guardar.Enabled = False Then
            guardar.Enabled = True
            cancelar.Enabled = True
            agregar.Enabled = False
            modificar.Enabled = False
            eliminar.Enabled = False
            imprimir.Enabled = False
            PanelArriba.Enabled = True
            PanelAbajo.Enabled = False
        Else
            cancelar.Enabled = False
            guardar.Enabled = False
            agregar.Enabled = True
            modificar.Enabled = False
            Eliminar.Enabled = True
            imprimir.Enabled = True
            PanelArriba.Enabled = False
            PanelAbajo.Enabled = True

        End If



    End Sub
    Private Sub CarnetempleadoBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CarnetempleadoBindingNavigatorSaveItem.Click
        Me.Validate()
        Me.CarnetempleadoBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.DbFireAndIceDataSet)

    End Sub

    Private Sub frmCarnetEmpleado_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'DbFireAndIceDataSet.empleados' table. You can move, or remove it, as needed.
        Me.EmpleadosTableAdapter.Fill(Me.DbFireAndIceDataSet.empleados)
        'TODO: This line of code loads data into the 'DbFireAndIceDataSet.carnetempleado' table. You can move, or remove it, as needed.
        Me.CarnetempleadoTableAdapter.Fill(Me.DbFireAndIceDataSet.carnetempleado)


    End Sub




    Private Sub IdempleadoLookUpEdit_EditValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles IdempleadoLookUpEdit.EditValueChanged



        Dim table1 As New dbFireAndIceDataSetTableAdapters.cargosTableAdapter
        txtnombre.EditValue = IdempleadoLookUpEdit.GetColumnValue("nombre")
        txtapellido.EditValue = IdempleadoLookUpEdit.GetColumnValue("apellido")

        If IsDBNull(PictureBox2) Then

            PictureBox2.Image = IdempleadoLookUpEdit.GetColumnValue("fotografia1")
        End If

        If IsDBNull(txtcargo.Text) Then
            txtcargo.Text = table1.FillBySeleccionaDescripcionCargo(Me.DbFireAndIceDataSet.cargos, IdempleadoLookUpEdit.GetColumnValue("idempleado"))
            MsgBox(txtcargo.Text)
        End If
       


    End Sub

    Private Sub guardar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles guardar.Click
        If IdempleadoLookUpEdit.Text = "" Then
            ErrorProvider1.SetError(IdempleadoLookUpEdit, "Seleccione un empleado")
            Return


        End If
        ErrorProvider1.SetError(IdempleadoLookUpEdit, Nothing)

        Try
            ' CarnetempleadoTableAdapter.InsertQuerycarnetempleado(CarnetempleadoidTextBox.Text, IdempleadoLookUpEdit.GetColumnValue("idempleado"), Date.Now)
            CarnetempleadoBindingNavigatorSaveItem.PerformClick()

            Me.CarnetempleadoTableAdapter.Fill(Me.DbFireAndIceDataSet.carnetempleado)
        Catch ex As Exception
            AlertControl1.AppearanceCaption.ForeColor = Color.Red
            AlertControl1.Show(Me, "Error", "Nose pudo guardar el registro")

        End Try
        AlertControl1.AppearanceCaption.ForeColor = Color.Green
        AlertControl1.Show(Me, "Advertencia", "Se guardó el resgistro satisfactoriamente")
        Mostrar()

    End Sub

    Private Sub agregar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles agregar.Click
        BindingNavigatorAddNewItem.PerformClick()
        mostrar()
    End Sub

    Private Sub cancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cancelar.Click
        ErrorProvider1.SetError(IdempleadoLookUpEdit, Nothing)
        Mostrar()

    End Sub

    Private Sub imprimir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles imprimir.Click
        GridControl1.ShowPrintPreview()
    End Sub

    Private Sub modificar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles modificar.Click
        Mostrar()
    End Sub

   

    Private Sub eliminar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles eliminar.Click
        Dim opcion As Integer
        opcion = MsgBox("¿Está seguro que desea eliminar el registro?", MsgBoxStyle.YesNo + MsgBoxStyle.Question, "Eliminar registro")
        If opcion = vbYes Then
            Try
                CarnetempleadoTableAdapter.DeleteQuery(IdempleadoLookUpEdit.Text)
                Me.CarnetempleadoTableAdapter.Fill(Me.DbFireAndIceDataSet.carnetempleado)
            Catch ex As Exception
                MsgBox("Lo sentimos, el registro no puede ser eliminado ya que está relacionado con otras tablas", MsgBoxStyle.Critical, "Error")
            End Try


        End If
    End Sub
End Class